(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

half(x) → if(ge(x, s(s(0))), x)
if(false, x) → 0
if(true, x) → s(half(p(p(x))))
p(0) → 0
p(s(x)) → x
ge(x, 0) → true
ge(0, s(x)) → false
ge(s(x), s(y)) → ge(x, y)
log(0) → 0
log(s(x)) → s(log(half(s(x))))

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

half(x) → if(ge(x, s(s(0))), x) [1]
if(false, x) → 0 [1]
if(true, x) → s(half(p(p(x)))) [1]
p(0) → 0 [1]
p(s(x)) → x [1]
ge(x, 0) → true [1]
ge(0, s(x)) → false [1]
ge(s(x), s(y)) → ge(x, y) [1]
log(0) → 0 [1]
log(s(x)) → s(log(half(s(x)))) [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

half(x) → if(ge(x, s(s(0))), x) [1]
if(false, x) → 0 [1]
if(true, x) → s(half(p(p(x)))) [1]
p(0) → 0 [1]
p(s(x)) → x [1]
ge(x, 0) → true [1]
ge(0, s(x)) → false [1]
ge(s(x), s(y)) → ge(x, y) [1]
log(0) → 0 [1]
log(s(x)) → s(log(half(s(x)))) [1]

The TRS has the following type information:
half :: 0:s → 0:s
if :: false:true → 0:s → 0:s
ge :: 0:s → 0:s → false:true
s :: 0:s → 0:s
0 :: 0:s
false :: false:true
true :: false:true
p :: 0:s → 0:s
log :: 0:s → 0:s

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:
none

And the following fresh constants: none

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

half(x) → if(ge(x, s(s(0))), x) [1]
if(false, x) → 0 [1]
if(true, x) → s(half(p(p(x)))) [1]
p(0) → 0 [1]
p(s(x)) → x [1]
ge(x, 0) → true [1]
ge(0, s(x)) → false [1]
ge(s(x), s(y)) → ge(x, y) [1]
log(0) → 0 [1]
log(s(x)) → s(log(half(s(x)))) [1]

The TRS has the following type information:
half :: 0:s → 0:s
if :: false:true → 0:s → 0:s
ge :: 0:s → 0:s → false:true
s :: 0:s → 0:s
0 :: 0:s
false :: false:true
true :: false:true
p :: 0:s → 0:s
log :: 0:s → 0:s

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

0 => 0
false => 0
true => 1

(8) Obligation:

Complexity RNTS consisting of the following rules:

ge(z, z') -{ 1 }→ ge(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
ge(z, z') -{ 1 }→ 1 :|: x >= 0, z = x, z' = 0
ge(z, z') -{ 1 }→ 0 :|: z' = 1 + x, x >= 0, z = 0
half(z) -{ 1 }→ if(ge(x, 1 + (1 + 0)), x) :|: x >= 0, z = x
if(z, z') -{ 1 }→ 0 :|: z' = x, x >= 0, z = 0
if(z, z') -{ 1 }→ 1 + half(p(p(x))) :|: z' = x, z = 1, x >= 0
log(z) -{ 1 }→ 0 :|: z = 0
log(z) -{ 1 }→ 1 + log(half(1 + x)) :|: x >= 0, z = 1 + x
p(z) -{ 1 }→ x :|: x >= 0, z = 1 + x
p(z) -{ 1 }→ 0 :|: z = 0

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V2),0,[half(V, Out)],[V >= 0]).
eq(start(V, V2),0,[if(V, V2, Out)],[V >= 0,V2 >= 0]).
eq(start(V, V2),0,[p(V, Out)],[V >= 0]).
eq(start(V, V2),0,[ge(V, V2, Out)],[V >= 0,V2 >= 0]).
eq(start(V, V2),0,[log(V, Out)],[V >= 0]).
eq(half(V, Out),1,[ge(V1, 1 + (1 + 0), Ret0),if(Ret0, V1, Ret)],[Out = Ret,V1 >= 0,V = V1]).
eq(if(V, V2, Out),1,[],[Out = 0,V2 = V3,V3 >= 0,V = 0]).
eq(if(V, V2, Out),1,[p(V4, Ret100),p(Ret100, Ret10),half(Ret10, Ret1)],[Out = 1 + Ret1,V2 = V4,V = 1,V4 >= 0]).
eq(p(V, Out),1,[],[Out = 0,V = 0]).
eq(p(V, Out),1,[],[Out = V5,V5 >= 0,V = 1 + V5]).
eq(ge(V, V2, Out),1,[],[Out = 1,V6 >= 0,V = V6,V2 = 0]).
eq(ge(V, V2, Out),1,[],[Out = 0,V2 = 1 + V7,V7 >= 0,V = 0]).
eq(ge(V, V2, Out),1,[ge(V8, V9, Ret2)],[Out = Ret2,V2 = 1 + V9,V8 >= 0,V9 >= 0,V = 1 + V8]).
eq(log(V, Out),1,[],[Out = 0,V = 0]).
eq(log(V, Out),1,[half(1 + V10, Ret101),log(Ret101, Ret11)],[Out = 1 + Ret11,V10 >= 0,V = 1 + V10]).
input_output_vars(half(V,Out),[V],[Out]).
input_output_vars(if(V,V2,Out),[V,V2],[Out]).
input_output_vars(p(V,Out),[V],[Out]).
input_output_vars(ge(V,V2,Out),[V,V2],[Out]).
input_output_vars(log(V,Out),[V],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [ge/3]
1. non_recursive : [p/2]
2. recursive : [half/2,if/3]
3. recursive : [log/2]
4. non_recursive : [start/2]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into ge/3
1. SCC is partially evaluated into p/2
2. SCC is partially evaluated into half/2
3. SCC is partially evaluated into log/2
4. SCC is partially evaluated into start/2

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations ge/3
* CE 14 is refined into CE [17]
* CE 12 is refined into CE [18]
* CE 13 is refined into CE [19]


### Cost equations --> "Loop" of ge/3
* CEs [18] --> Loop 12
* CEs [19] --> Loop 13
* CEs [17] --> Loop 14

### Ranking functions of CR ge(V,V2,Out)
* RF of phase [14]: [V,V2]

#### Partial ranking functions of CR ge(V,V2,Out)
* Partial RF of phase [14]:
- RF of loop [14:1]:
V
V2


### Specialization of cost equations p/2
* CE 9 is refined into CE [20]
* CE 8 is refined into CE [21]


### Cost equations --> "Loop" of p/2
* CEs [20] --> Loop 15
* CEs [21] --> Loop 16

### Ranking functions of CR p(V,Out)

#### Partial ranking functions of CR p(V,Out)


### Specialization of cost equations half/2
* CE 11 is refined into CE [22,23]
* CE 10 is refined into CE [24]


### Cost equations --> "Loop" of half/2
* CEs [24] --> Loop 17
* CEs [23] --> Loop 18
* CEs [22] --> Loop 19

### Ranking functions of CR half(V,Out)
* RF of phase [17]: [V-1]

#### Partial ranking functions of CR half(V,Out)
* Partial RF of phase [17]:
- RF of loop [17:1]:
V-1


### Specialization of cost equations log/2
* CE 16 is refined into CE [25,26,27]
* CE 15 is refined into CE [28]


### Cost equations --> "Loop" of log/2
* CEs [28] --> Loop 20
* CEs [27] --> Loop 21
* CEs [26] --> Loop 22
* CEs [25] --> Loop 23

### Ranking functions of CR log(V,Out)
* RF of phase [21,22]: [V-1]

#### Partial ranking functions of CR log(V,Out)
* Partial RF of phase [21,22]:
- RF of loop [21:1]:
V/2-1
- RF of loop [22:1]:
V-1


### Specialization of cost equations start/2
* CE 2 is refined into CE [29,30,31,32,33,34]
* CE 3 is refined into CE [35]
* CE 4 is refined into CE [36,37,38,39]
* CE 5 is refined into CE [40,41]
* CE 6 is refined into CE [42,43,44,45]
* CE 7 is refined into CE [46,47,48]


### Cost equations --> "Loop" of start/2
* CEs [43] --> Loop 24
* CEs [29,30,31,32,33,34,37,38,39,41,44,45,47,48] --> Loop 25
* CEs [35,36,40,42,46] --> Loop 26

### Ranking functions of CR start(V,V2)

#### Partial ranking functions of CR start(V,V2)


Computing Bounds
=====================================

#### Cost of chains of ge(V,V2,Out):
* Chain [[14],13]: 1*it(14)+1
Such that:it(14) =< V

with precondition: [Out=0,V>=1,V2>=V+1]

* Chain [[14],12]: 1*it(14)+1
Such that:it(14) =< V2

with precondition: [Out=1,V2>=1,V>=V2]

* Chain [13]: 1
with precondition: [V=0,Out=0,V2>=1]

* Chain [12]: 1
with precondition: [V2=0,Out=1,V>=0]


#### Cost of chains of p(V,Out):
* Chain [16]: 1
with precondition: [V=0,Out=0]

* Chain [15]: 1
with precondition: [V=Out+1,V>=1]


#### Cost of chains of half(V,Out):
* Chain [[17],19]: 5*it(17)+1*s(3)+3
Such that:aux(4) =< 2*Out
it(17) =< aux(4)
s(3) =< aux(4)*2

with precondition: [V=2*Out,V>=2]

* Chain [[17],18]: 5*it(17)+1*s(3)+1*s(4)+3
Such that:s(4) =< 1
aux(5) =< V
it(17) =< aux(5)
s(3) =< aux(5)*2

with precondition: [V=2*Out+1,V>=3]

* Chain [19]: 3
with precondition: [V=0,Out=0]

* Chain [18]: 1*s(4)+3
Such that:s(4) =< 1

with precondition: [V=1,Out=0]


#### Cost of chains of log(V,Out):
* Chain [[21,22],23,20]: 4*it(21)+4*it(22)+1*s(5)+1*s(20)+10*s(21)+2*s(22)+5
Such that:s(5) =< 1
aux(13) =< V
aux(14) =< 2*V
aux(15) =< V/2
aux(6) =< aux(13)
it(21) =< aux(13)
it(22) =< aux(13)
it(22) =< aux(14)
aux(6) =< aux(15)
it(21) =< aux(15)
s(20) =< aux(6)
s(21) =< aux(14)
s(22) =< aux(14)*2

with precondition: [Out>=2,V+2>=2*Out]

* Chain [23,20]: 1*s(5)+5
Such that:s(5) =< 1

with precondition: [V=1,Out=1]

* Chain [20]: 1
with precondition: [V=0,Out=0]


#### Cost of chains of start(V,V2):
* Chain [26]: 3
with precondition: [V=0]

* Chain [25]: 6*s(27)+11*s(29)+2*s(30)+11*s(37)+2*s(38)+4*s(51)+4*s(52)+1*s(53)+10*s(54)+2*s(55)+6
Such that:s(48) =< 2*V
s(49) =< V/2
aux(16) =< 1
aux(17) =< V
aux(18) =< V2
s(27) =< aux(16)
s(37) =< aux(17)
s(29) =< aux(18)
s(30) =< aux(18)*2
s(38) =< aux(17)*2
s(50) =< aux(17)
s(51) =< aux(17)
s(52) =< aux(17)
s(52) =< s(48)
s(50) =< s(49)
s(51) =< s(49)
s(53) =< s(50)
s(54) =< s(48)
s(55) =< s(48)*2

with precondition: [V>=1]

* Chain [24]: 1
with precondition: [V2=0,V>=0]


Closed-form bounds of start(V,V2):
-------------------------------------
* Chain [26] with precondition: [V=0]
- Upper bound: 3
- Complexity: constant
* Chain [25] with precondition: [V>=1]
- Upper bound: 24*V+12+nat(V2)*15+28*V
- Complexity: n
* Chain [24] with precondition: [V2=0,V>=0]
- Upper bound: 1
- Complexity: constant

### Maximum cost of start(V,V2): max([2,24*V+11+nat(V2)*15+28*V])+1
Asymptotic class: n
* Total analysis performed in 239 ms.

(10) BOUNDS(1, n^1)